
using System;
using System.Configuration;
using System.Net.Mail;
using System.Text;

namespace emp.Utility
{
    public class SendMail
    {
        public static bool SendMails(string fromUser, string fromUserName, string toUser, string toUserName,string cc, string subjectNm, string bodyAll)
        {
            bool ret = false;
            try
            {
                MailMessage mm = new MailMessage();
                mm.From = new MailAddress(fromUser, fromUserName, Encoding.UTF8);
                mm.To.Add(toUser);
                string[] listc = null;
                try
                {
                    if (cc != null && cc != "")
                    {
                        listc = cc.Split(',');
                        for (int i = 0; i < listc.Length; i++)
                        {
                            mm.CC.Add(listc[i].ToString());
                        }
                    }
                }
                catch (Exception list)
                {
                }
                //mm.CC.Add(cc);
                mm.Subject = subjectNm;
                mm.SubjectEncoding = Encoding.UTF8;
                mm.Body = bodyAll;
                mm.BodyEncoding = Encoding.UTF8;
                mm.IsBodyHtml = true;
                mm.Priority = MailPriority.High;

                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("leads_system@audi.cn", "leadssystemmail");
                client.Host = "61.135.207.62";
                client.Send(mm);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
        public static bool SendMails(string fromUser, string fromUserName, string toUser, string toUserName, string cc,string bcc, string subjectNm, string bodyAll)
        {
            bool ret = false;
            try
            {
                MailMessage mm = new MailMessage();
                mm.From = new MailAddress(fromUser, fromUserName, Encoding.UTF8);
                mm.To.Add(toUser);
                string[] listc = null;
                string[] listbcc = null;
                try
                {
                    if (cc != null && cc != "")
                    {
                        listc = cc.Split(',');
                        for (int i = 0; i < listc.Length; i++)
                        {
                            mm.CC.Add(listc[i].ToString());
                        }
                    }
                }
                catch (Exception list)
                {
                }
                try
                {
                    if (bcc != null && bcc != "")
                    {
                        listbcc = bcc.Split(',');
                        for (int j = 0; j < listbcc.Length; j++)
                        {
                            mm.Bcc.Add(listbcc[j].ToString());
                        }
                    }
                }
                catch (Exception list1)
                {
                }
                //mm.CC.Add(cc);
                mm.Subject = subjectNm;
                mm.SubjectEncoding = Encoding.UTF8;
                mm.Body = bodyAll;
                mm.BodyEncoding = Encoding.UTF8;
                mm.IsBodyHtml = true;
                mm.Priority = MailPriority.High;

                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("leads_system@audi.cn", "leadssystemmail");
                client.Host = "61.135.207.62";
                client.Send(mm);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }

        public static bool SendMails(string fromUser, string fromUserName, string toUser, string toUserName, string subjectNm, string bodyAll)
        {
            bool ret = false;
            try
            {
                MailMessage mm = new MailMessage();
                mm.From = new MailAddress(fromUser, fromUserName, Encoding.UTF8);
                mm.To.Add(toUser);
               // mm.Bcc.Add(toUser); 
                mm.Subject = subjectNm;
                mm.SubjectEncoding = Encoding.UTF8;
                mm.Body = bodyAll;
                mm.BodyEncoding = Encoding.UTF8;
                mm.IsBodyHtml = true;
                mm.Priority = MailPriority.High;

                SmtpClient client = new SmtpClient();
                client.Credentials = new System.Net.NetworkCredential("leads_system@audi.cn", "leadssystemmail");
                client.Host = "61.135.207.62";
                client.Send(mm);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }

        public static bool SendMails_test(string fromUser, string fromUserName, string toUser, string toUserName, string subjectNm, string bodyAll, string credentialEmail, string credentialName,string strSMTP)
        {
            bool ret = false;
            try
            {
                MailMessage mm = new MailMessage();
                mm.From = new MailAddress(fromUser, fromUserName, Encoding.UTF8);
                mm.To.Add(toUser);
                mm.Subject = subjectNm;
                mm.SubjectEncoding = Encoding.UTF8;
                mm.Body = bodyAll;
                mm.BodyEncoding = Encoding.UTF8;
                mm.IsBodyHtml = true;
                mm.Priority = MailPriority.High;

                SmtpClient client = new SmtpClient();
                //client.Credentials = new System.Net.NetworkCredential("thepact@keepwalking.asia", "thepact_asia");
                client.Credentials = new System.Net.NetworkCredential(credentialEmail, credentialName);
                client.Host = strSMTP;
                client.Send(mm);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
    }
}
